import {ref} from "vue"

//定位 持续导航
export const aMapLoc = () => {
	//持续定位插件对象
	const loc = uni.requireNativePlugin('AMap-Loc');

	loc.updatePrivacyShow(true, true);
	loc.updatePrivacyAgree(true);
	
	//开启后台保活
	function enableBackgroundLocation(callback) {
		//android特有的接口
		//检查是否允许通知，oppo vivo等部分手机默认不允许通知
		if (loc.areNotificationsEnabled()) {
			//是否忽略电池优化，vivo部分手机需要忽略电池优化，保活才不被杀掉
			if (loc.isIgnoringBatteryOptimizations()) {
				loc.enableBackgroundLocation({
					contentTitle:"泽佑司机端-送货中",
					contentText:"正在后台运行"
				});
			} else {
				//请求忽略电池优化
				loc.requestIgnoreBatteryOptimizations();
			}
			callback(true);
		} else {
			//打开设置通知
			// openSettingFun();
			console.log('判断')
			callback(false);
		}
	}
	
	//关闭后台保活
	function disableBackgroundLocation() {
		//android特有的接口
		//停止后台保活定位服务
		var removeNotification = true;
		loc.disableBackgroundLocation(removeNotification);
	}
	
	//打开设置通知
	function openSettingFun(){
		loc.openSetting();
	}
	
	return {
	    enableBackgroundLocation,
			openSettingFun
	}
}